<template>
    <div class="relation-file">
        <cardList :columns="columns" :data="tableData.list" v-show="tableData.total"></cardList>
        <Page
            v-show="tableData.total"
            :total="tableData.total"
            :page-size="queryParams.pageSize"
            :current="queryParams.pageIndex"
            show-total
            show-elevator
            @on-change="changePageNow"
        />
        <no-data text="暂无信息" v-show="!tableData.total"></no-data>
    </div>
</template>

<script>
import { getRelationFileList } from '@/api/scientific/contentRelation';
import NoData from '@/components/common/no-data';
import cardList from '@/components/list-template/card-list/cardList.vue';

export default {
    name: 'RelationFile',
    components: { NoData, cardList },
    props: {
        columns: {
            type: Array,
            default: () => [],
        },
        type: {
            type: Number,
            default: 1,
        },
    },
    data() {
        return {
            queryParams: {
                pageIndex: 1,
                pageSize: 10,
                type: '',
                contentId: this.$route.query.id,
            },
            tableData: {
                list: [],
                total: 0,
            },
        };
    },
    filters: {},
    watch: {},
    mounted() {
        this.queryParams.type = this.type;
    },
    methods: {
        // 查询指定页数据
        changePageNow(val) {
            this.queryParams.pageIndex = val;
            this.getTableList();
        },
        // 查询列表
        getTableList() {
            getRelationFileList(this.queryParams)
                .then(({ code, message, data = {} }) => {
                    if (code !== 1) {
                        this.$Message.warning(message);
                        return;
                    }
                    this.tableData.list = data.items || [];
                    this.tableData.total = data.total;
                })
                .catch(() => {
                    this.$Message.error('获取科研关联文件异常');
                });
        },
    },
};
</script>

<style scoped>
.relation-file {
    height: 100%;
}
.relation-file /deep/ .ivu-page {
    text-align: center;
    margin-top: 20px;
}
</style>
